package pap7.HilarionRojas;

/**
 * 
 * @author HilarionRojas
 *
 */
public class Calculadora {

	public int sumar(String expresion) {
		if (tieneSeparador(expresion)) {
			String[] tokens = expresion.split(",");
			return convertirEntero(tokens[0]) + convertirEntero(tokens[1]);
		} else if (expresion.equals("")) {
			return 0;
		} else {
			return convertirEntero(expresion);
		}

	}

	private boolean tieneSeparador(String expresion) {
		return expresion.indexOf(",") != -1;
	}

	private int convertirEntero(String expresion) {
		return Integer.parseInt(expresion);
	}

}
